/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './loginController';
import * as API from './types';

/** 账号登录 POST /api/login/account */
export function useAccountUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultxitongdengluVo) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.accountUsingPost,
    onSuccess(data: API.AjaxResultxitongdengluVo) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 公众号链接 GET /api/login/codeUrl */
export function codeUrlUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.codeUrlUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.codeUrlUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['codeUrlUsingGet', options],
  });
}

/** PC扫码链接 GET /api/login/getScanCode */
export function scanCodeUrlUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.scanCodeUrlUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.scanCodeUrlUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['scanCodeUrlUsingGet', options],
  });
}

/** 退出登录 POST /api/login/logout */
export function useLogoutUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.logoutUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 绑定小程序 POST /api/login/mnpAuthBind */
export function useMnpAuthBindUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.mnpAuthBindUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 微信登录 POST /api/login/mnpLogin */
export function useMnpLoginUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultxitongdengluVo) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.mnpLoginUsingPost,
    onSuccess(data: API.AjaxResultxitongdengluVo) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 绑定微信公众号 POST /api/login/oaAuthBind */
export function useOaAuthBindUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.oaAuthBindUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 公众号登录 POST /api/login/oaLogin */
export function useOaLoginUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultxitongdengluVo) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.oaLoginUsingPost,
    onSuccess(data: API.AjaxResultxitongdengluVo) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 注册账号 POST /api/login/register */
export function useRegisterUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.registerUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** PC扫码登录 POST /api/login/scanLogin */
export function useScanLoginUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.scanLoginUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
